package com.itcast.jdbc.test03;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class JdbcTest03 {

    public static void main(String[] args) throws SQLException {

        //练习更新操作
        Brand brand=new Brand(4,"华为手机","华为公司",1000,"苹果手机挺好用的!!",1);

        int i = updateBrand(brand);



    }

    private static int updateBrand(Brand brand) throws SQLException {
//获取连接
        Connection connection = DatasourceUtils.getConnection();

        //编写sql
        String sql="update tb_brand set brand_name=?,company_name=?,ordered=?,description=?,status=? where id=? ";
        //绑定preparedStatement的参数
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,brand.getBrandName());
        preparedStatement.setString(2,brand.getCompanyName());
        preparedStatement.setInt(3,brand.getOrdered());
        preparedStatement.setString(4,brand.getDescription());
        preparedStatement.setInt(5,brand.getStatus());
        preparedStatement.setInt(6,brand.getId());
        //执行
        int i = preparedStatement.executeUpdate();

        //关闭资源
        preparedStatement.close();
        //归还连接给连接池
        connection.close();

        return i;
    }


}